/**
 * 
 */
package com.sad.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.sad.dao.RecordManager;
import com.sad.model.Applyreturn;
import com.sad.model.JsonObject;
import com.sad.service.BaseService;
import com.sad.util.G;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class ApplyreturnService extends BaseService<Map> {

	@Override
	public List<Map> findList(Map parms) {

		String pageid = StringUtils.defaultString((String) parms.get(G.K.pageid), "applyreturn");

		JsonObject jObject = (JsonObject) RecordManager.loadRecord(pageid).get(parms);

		int totalcount = 0;
		if (jObject != null && jObject.getPage() != null) {
			totalcount = jObject.getPage().getTotalcount();
		}

		List<Map> wishList = new ArrayList<Map>();

		try {
			if (jObject != null && jObject.getInfo() != null) {
				List<Applyreturn> results = jObject.getInfo();
				for (Applyreturn w : results) {
					Map map = new HashMap();
					if (w.getUser() != null) {
						map.put("username", w.getUser().getUsername());
						map.put("address", w.getUser().getAddress());
						map.put("mobile", w.getUser().getMobile());
					} else {
						map.put("username", "");
						map.put("address", "");
						map.put("mobile", "");
					}
					if (w.getToy() != null) {
						map.put("toyname", w.getToy().getToyName());
						map.put("toytheme", w.getToy().getToyTheme());
					} else {
						map.put("toyname", "");
						map.put("toytheme", "");
					}

					map.put("status", w.getStatus());
					if (w.getApplytime() != null) {
						map.put("applytime", w.getApplytime().getDateTimeStr());
					} else {
						map.put("applytime", "");
					}

					wishList.add(map);
				}
			}

		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}

		Map page = new HashMap();
		page.put("totalcount", totalcount);
		wishList.add(0, page);

		return wishList;
	}
}
